package com.pkufinalproject.cleverreminder.hibernate.entity;

import lombok.Data;
import org.json.JSONObject;
import org.apache.commons.lang.RandomStringUtils;

import java.util.HashMap;
import java.util.Map;

@Data
public class RequestReminder extends Reminder {
    private String token;

    /**
     * 为RequestReminder随机生成一个token作为请求提醒码
     * @return String, 生成的token
     */
    public String generateToken() {
        int tokenLength = 6;
        String token = RandomStringUtils.randomAlphabetic(tokenLength);
        this.token = token;
        return token;
    }

    @Override
    public String toString() {
        Map<String, String> memberMap = new HashMap<String, String>();
        memberMap.put("id", id.toString());
        memberMap.put("title", title);
        memberMap.put("createTime", createTime.toString());
        memberMap.put("enabled", enabled.toString());
        memberMap.put("token", token);
        JSONObject memberJson = new JSONObject(memberMap);
        return memberJson.toString();
    }
}
